// @Author EthanScriptOn
// @Desc
package log_worker

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_basic_components/pool"
	"gitee.com/fatzeng/srf_switch_basic_components/queue"
	"gitee.com/fatzeng/srf_switch_log/log_task"
)

type LoggerFormatWorker struct {
	*pool.DefaultWorker
}

func GenerateLoggerFormatWorker(queue queue.Queue, weight int) *LoggerFormatWorker {
	return &LoggerFormatWorker{
		DefaultWorker: pool.GenerateDefaultWorker(queue, weight),
	}
}

// LoggerFormatOption Formatting of logs
func (l *LoggerFormatWorker) LoggerFormatOption(task pool.Task) error {
	unitTask, ok := task.(*log_task.LogUnitTask)
	if !ok {
		return fmt.Errorf("LoggerFormatWorker Submit task error task is %v", task)
	}
	// Execute formatting of logs
	if err := unitTask.Execute(); err != nil {
		return fmt.Errorf("LoggerFormatWorker Submit task error execute task err is %v, execute task is %v", err, task)
	}
	return nil
}
